

export enum Route {
    HomePage,
    SettingPage,
    MenuPage
}

export global System {

    // 屏幕宽高
    out property <length> screen_width:240px;
    out property <length> screen_height:240px;

    // 路由页面
    in-out property <Route> route:Route.HomePage;

    // 帧率
    in-out property <int> fps:0;

    public function to_home() {
        route = Route.HomePage;
    }

    public function to_menu() {
        route = Route.MenuPage;
    }

}

export global Setting {
    // 开启fps帧率显示
    in-out property <bool> fps:true;
}



export struct MenuItem {
    name:string,
    icon:image
}
export global Menu {
    in-out property <[MenuItem]> menu_item:[
        {name:"小狗",icon: @image-url("../assets/dog.png")},
        {name:"小狗",icon: @image-url("../assets/cat.png")},
        {name:"小羊",icon: @image-url("../assets/sheep.png")},
        {name:"小猫",icon: @image-url("../assets/cat.png")},
        {name:"小狗",icon: @image-url("../assets/dog.png")},
        {name:"小羊",icon: @image-url("../assets/sheep.png")},
        {name:"小猫",icon: @image-url("../assets/cat.png")},
        {name:"小狗",icon: @image-url("../assets/dog.png")},
    ];

    // 菜单列表项的子item的高度，决定了页面可以显示的item数量
    out property <int> list_item_count : 4;
    out property <length> item_height:System.screen_height / list_item_count;

    // 当前选择的item索引
    in-out property <int> current_index:0;

    // 列表偏移
    in-out property <length> list_pos_y:0px;

    // 选择框偏移
    in-out property <length> border_y:0px;

    // item的数量
    in-out property <int> count : Menu.menu_item.length;
    // 列表的最大高度
    in-out property <length> list_max_height : item_height * count;

    // 上一个列表
   public function last() {
        if(Menu.border_y == 0){
            if(Menu.list_pos_y == 0){

            }else{
                Menu.list_pos_y += Menu.item_height;
            }
        }else{
            Menu.border_y -= Menu.item_height;
        }

        // 修改当前选择的索引
        if(Menu.current_index > 0){
            Menu.current_index -= 1;
        }
    }

    // 下一个列表
    public function next() {
        if(Menu.border_y >= Menu.item_height * (Menu.list_item_count - 1)){
            if(-Menu.list_pos_y >= Menu.item_height * (Menu.count - Menu.list_item_count)){

            }else{
                Menu.list_pos_y -= Menu.item_height;
            }
        }else{
            Menu.border_y += Menu.item_height;
        }

        // 修改当前选择的索引
        if(Menu.current_index < Menu.count - 1){
            Menu.current_index += 1;
        }
    }
}



export global LocalTime {
    in-out property <int> hour:12;
    in-out property <int> minute:12;
    in-out property <int> scond:30;

    in-out property <int> year:2025;
    in-out property <int> month:12;
    in-out property <int> day:12;

    in-out property <int> week:1;
    private property <[string]> weeks:["周日","周一","周二","周三","周四","周五","周六"];
    in-out property <string> week_cn:weeks[week];

}